package com.education.wisdom.controller.app;

import com.education.wisdom.pojo.JrReportTab;
import com.education.wisdom.pojo.JrReportform;
import com.education.wisdom.pojo.dto.JrReportformDTO;
import com.education.wisdom.service.IJrReportformService;
import com.education.wisdom.service.impl.JrReportTabServiceImpl;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

import static com.education.common.core.BaseController.writeJSON;

/**
 * 达人视频举报模块
 *
 * @author d
 * @date 2020-07-11
 */
@RestController
@RequestMapping("/jrReportForm")
public class AppReportformController {


    private final IJrReportformService jrReportformService;
    private final JrReportTabServiceImpl reportTabService;

    @Autowired
    public AppReportformController(IJrReportformService jrReportformService, JrReportTabServiceImpl reportTabService) {
        this.jrReportformService = jrReportformService;
        this.reportTabService = reportTabService;
    }

    /**
     * 查询举报列表
     */
    @GetMapping("/list")
    public void list(JrReportform jrReportform, HttpServletResponse response) throws Exception {
        List<JrReportform> list = jrReportformService.selectJrReportformList(jrReportform);
        writeJSON(list, response, "200", "成功");
    }

    /**
     * 查询举报列表
     * catalogId 达人视频id
     *
     * @param jrReportform
     * @param response
     * @throws Exception
     */
    @GetMapping("/pageList")
    public void pageList(JrReportformDTO jrReportform, HttpServletResponse response) throws Exception {
        PageInfo<JrReportformDTO> list = jrReportformService.pageList(jrReportform);
        writeJSON(list, response, "200", "成功");
    }

    /**
     * 查询举报标签列表
     */
    @GetMapping("/labelList")
    public void labelList(JrReportTab reportTab, HttpServletResponse response) throws Exception {
        //查询全部举报标签 无条件
        List<JrReportTab> tabs = reportTabService.selectJrReportTabList(reportTab);
        writeJSON(tabs, response, "200", "成功");
    }


    /**
     * 新增保存举报
     */
    @PostMapping("/add")
    public void addSave(JrReportform jrReportform, HttpServletResponse response) throws Exception {
        // 举报内容 职业大人视频id    标签id    举报人id
        if (jrReportform.getLabelId() == null) {
            writeJSON("", response, "201", "请选择标签", "");
        }
        if (jrReportform.getCatalogId() != null && jrReportform.getUserId() != null) {
            jrReportformService.insertJrReportform(jrReportform);
            writeJSON("", response, "200", "举报成功", "");
        }
        writeJSON("", response, "201", "缺少参数", "");
    }


    /**
     * 删除举报
     */
    @PostMapping("/del")
    public void remove(Integer id, HttpServletResponse response) throws Exception {
        if (id != null) {
            jrReportformService.deleteJrReportformById(id);
            writeJSON("", response, "200", "取消举报成功", "");
        }
        writeJSON("", response, "201", "缺少参数id", "");
    }


}